package com.quan.common.configuration;

import org.n3r.idworker.IdWorker;
import org.n3r.idworker.Sid;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分布式ID生成器
 * 将IdWorker注入到Spring容器中
 * @author yhaoquan
 *
 */
@Configuration
public class IdWorkerConfiguration {
	
	@Bean
	public IdWorker idWorker() {
		IdWorker idWorker = new IdWorker(11) ;
		return idWorker ;
	}
	
	public static void main(String[] args) {
		IdWorker idWorker = new IdWorker(3) ;
		System.out.println(idWorker.getWorkerId());
		System.out.println(idWorker.getLastMillis());
		System.out.println(idWorker.nextId());
		System.out.println(idWorker.nextId());
		System.out.println(Sid.nextShort());
		System.out.println(Sid.nextShort());
		System.out.println(Sid.next());
		System.out.println(Sid.next());
		System.out.println(Sid.next());
	}

}
